import { getTimeData,addTimeData,operate } from './service';
import { message } from 'antd';
import moment from 'moment'
const creator=(type,payload)=>({type,payload})
export default {
  namespace: 'timeArrow',
  state: {
      timeArrowData:[],
      legendData:[],//示例数据
      seriesData:[],//饼状图数据
      diaries:[]
  },
  effects: {
    //获取日记列表
    *getTimeData({payload},{call,put}) {
        const res=yield call(getTimeData,payload)
        if(res.httpStatus===200){
           
            let legendData=[];
            let seriesData=[];
            
            res.data.map(item=>{
              let obj={}
              obj.name=item.content;
              obj.value=moment(item.end).diff(item.start,'minutes');
              legendData.push(item.content)
              seriesData.push(obj)
            })
            yield put(creator('saveTimeData',res.data))
            yield put(creator('saveData',{legendData,seriesData}))
        }
    },
    *addTimeData({payload},{call,put}){
      const res=yield call(addTimeData,payload)
      return res;
     
    }
  },
  reducers: {
    saveTimeData(state,{payload}){
        return {
            ...state,
            timeArrowData:payload
        }
    },
    saveData(state,{payload}){
      const {legendData,seriesData}=payload;
      return {
        ...state,
        legendData,
        seriesData,
      }
    }
  },
};
